import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import java.awt.Color;
import javax.swing.JLabel;
import javax.swing.GroupLayout;
import javax.swing.GroupLayout.Alignment;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JTextArea;
import javax.swing.LayoutStyle.ComponentPlacement;
import javax.swing.JTextField;
import javax.swing.JButton;


public class StoreView extends JFrame  {

	private JPanel contentPane;
	private JTextField quantityToBuyTextFields[];
	private JLabel quantityYouHaveLabels[];
	private JButton buyBtn;
	private StoreModel sm;
	private JTextArea currCash;
	private MainPlayerModel mm;
	private MainPlayerView mv;

	/**
	 * Create the frame.
	 */
	public StoreView(StoreModel sm, MainPlayerModel mm) {
		this.sm = sm;
		this.mm = mm;
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBackground(new Color(218, 165, 32));
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JLabel lblRation = new JLabel("Store");
		lblRation.setFont(new Font("Tahoma", Font.BOLD, 12));
		
//<<<<<<< .mine
		
		JTextArea txtrYouHave = new JTextArea();
		//txtrYouHave.setText("You have: $");
//=======
		currCash = new JTextArea();
		
		currCash.setText("You have: $ " + mm.getTotalCash(mm.getProfession()));
//>>>>>>> .r44
		
		quantityToBuyTextFields = new JTextField[7];
		quantityYouHaveLabels = new JLabel[7];
		
		for(int i = 0; i < quantityToBuyTextFields.length; i++)
		{
			quantityToBuyTextFields[i] = new JTextField();
			quantityToBuyTextFields[i].setColumns(10);
		}
		
		quantityYouHaveLabels[0] = new JLabel("1");
		for(int i = 1; i < quantityYouHaveLabels.length; i++)
		{
			quantityYouHaveLabels[i] = new JLabel("0");
		}
		
		
		JLabel lblGas = new JLabel("Gas @ $80.00");
		lblGas.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblFood = new JLabel("Food @ $0.20 per pound");
		lblFood.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblClothes = new JLabel("Clothes @ $10.00 per set");
		lblClothes.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblAmmunitionPer = new JLabel("Ammunition @ $10.00 per box");
		lblAmmunitionPer.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblSpareWheels = new JLabel("Spare wheels @ $20.00");
		lblSpareWheels.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblSpareAxles = new JLabel("Spare Axles @ $20.00");
		lblSpareAxles.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblSpareEngine = new JLabel("Spare engine @ $20.00");
		lblSpareEngine.setFont(new Font("Tahoma", Font.PLAIN, 12));
		
		JLabel lblNewLabel = new JLabel("Qty to Buy");
		lblNewLabel.setFont(new Font("Tahoma", Font.BOLD, 11));
		
		JLabel lblNewLabel_1 = new JLabel("Qty You Have");
		lblNewLabel_1.setFont(new Font("Tahoma", Font.BOLD, 11));
		

		
		buyBtn = new JButton("Buy");
		
		GroupLayout gl_contentPane = new GroupLayout(contentPane);
		gl_contentPane.setHorizontalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addContainerGap()
					.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addComponent(lblRation, GroupLayout.PREFERRED_SIZE, 424, GroupLayout.PREFERRED_SIZE)
							.addContainerGap())
						.addGroup(gl_contentPane.createSequentialGroup()
							.addComponent(currCash, GroupLayout.PREFERRED_SIZE, 138, GroupLayout.PREFERRED_SIZE)
							.addContainerGap(276, Short.MAX_VALUE))
						.addGroup(Alignment.TRAILING, gl_contentPane.createSequentialGroup()
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addComponent(quantityToBuyTextFields[2], GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
										.addComponent(quantityToBuyTextFields[5], GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
										.addComponent(quantityToBuyTextFields[1], GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
										.addComponent(quantityToBuyTextFields[0], GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
										.addComponent(quantityToBuyTextFields[4], GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
										.addComponent(quantityToBuyTextFields[3], GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE))
									.addPreferredGap(ComponentPlacement.RELATED)
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addComponent(lblAmmunitionPer)
										.addComponent(lblSpareWheels, GroupLayout.DEFAULT_SIZE, 195, Short.MAX_VALUE)
										.addComponent(lblClothes, GroupLayout.PREFERRED_SIZE, 176, GroupLayout.PREFERRED_SIZE)
										.addComponent(lblFood)
										.addComponent(lblGas)
										.addComponent(lblSpareAxles, GroupLayout.PREFERRED_SIZE, 195, GroupLayout.PREFERRED_SIZE)))
								.addGroup(gl_contentPane.createSequentialGroup()
									.addComponent(quantityToBuyTextFields[6], GroupLayout.PREFERRED_SIZE, 34, GroupLayout.PREFERRED_SIZE)
									.addPreferredGap(ComponentPlacement.RELATED)
									.addComponent(lblSpareEngine)))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
								.addComponent(lblNewLabel_1)
								.addComponent(quantityYouHaveLabels[0])
								.addComponent(quantityYouHaveLabels[1], GroupLayout.PREFERRED_SIZE, 6, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[2], GroupLayout.PREFERRED_SIZE, 6, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[3], GroupLayout.PREFERRED_SIZE, 6, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[4], GroupLayout.PREFERRED_SIZE, 6, GroupLayout.PREFERRED_SIZE)
								.addGroup(gl_contentPane.createSequentialGroup()
									.addGroup(gl_contentPane.createParallelGroup(Alignment.LEADING)
										.addComponent(quantityYouHaveLabels[5], GroupLayout.PREFERRED_SIZE, 6, GroupLayout.PREFERRED_SIZE)
										.addComponent(quantityYouHaveLabels[6], GroupLayout.PREFERRED_SIZE, 6, GroupLayout.PREFERRED_SIZE))
									.addGap(76)
									.addComponent(buyBtn)))
							.addGap(25))))
		);
		gl_contentPane.setVerticalGroup(
			gl_contentPane.createParallelGroup(Alignment.LEADING)
				.addGroup(gl_contentPane.createSequentialGroup()
					.addComponent(lblRation)
					.addGroup(gl_contentPane.createParallelGroup(Alignment.TRAILING)
						.addGroup(gl_contentPane.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(currCash, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
							.addGap(7)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(lblNewLabel)
								.addComponent(lblNewLabel_1))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(quantityToBuyTextFields[0], GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblGas)
								.addComponent(quantityYouHaveLabels[0]))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(quantityToBuyTextFields[1], GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblFood, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[1]))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(quantityToBuyTextFields[2], GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblClothes, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[2]))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(quantityToBuyTextFields[3], GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblAmmunitionPer, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[3]))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(quantityToBuyTextFields[4], GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblSpareWheels, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[4]))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(quantityToBuyTextFields[5], GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblSpareAxles, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[5]))
							.addPreferredGap(ComponentPlacement.RELATED)
							.addGroup(gl_contentPane.createParallelGroup(Alignment.BASELINE)
								.addComponent(quantityToBuyTextFields[6], GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
								.addComponent(lblSpareEngine, GroupLayout.PREFERRED_SIZE, 15, GroupLayout.PREFERRED_SIZE)
								.addComponent(quantityYouHaveLabels[6]))
							.addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
						.addGroup(gl_contentPane.createSequentialGroup()
							.addPreferredGap(ComponentPlacement.RELATED)
							.addComponent(buyBtn)
							.addContainerGap())))
		);
		contentPane.setLayout(gl_contentPane);
	}

	public void addUserActionListener(ActionListener al)
	{
		buyBtn.addActionListener(al);
		
		for(int i = 0; i < quantityToBuyTextFields.length; i++)
		{
			quantityToBuyTextFields[i].addActionListener(al);
		}
	}
	
	public JTextField[] getTextFields()
	{
		return quantityToBuyTextFields;
	}
	
	public JLabel[] getLabels()
	{
		return quantityYouHaveLabels;
	}
	
	public void setLabel(int index, String lbl)
	{
		quantityYouHaveLabels[index].setText(lbl);
	}
	
	public void setCashText(double cash)
	{
		//currCash.setText("You have: $ " + mm.getTotalCash());
	}
}
